package com.example.test_flutter

import android.content.Intent
import android.os.Bundle
import android.view.View
import android.view.Window
import androidx.appcompat.app.AppCompatActivity
import com.idlefish.flutterboost.FlutterBoost
import com.idlefish.flutterboost.FlutterBoostRouteOptions
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.android.FlutterFragment


class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        findViewById<View>(R.id.gotoFlutterActivity).setOnClickListener {
            startActivity(
                FlutterActivity
                    .withNewEngine()
                    .initialRoute("debug")
                    .build(this)
            )
        }
        findViewById<View>(R.id.gotoFlutterFragment).setOnClickListener {
            startActivity(Intent(this, FlutterFragmentActivity::class.java))
        }
        findViewById<View>(R.id.gotoFlutterBoost).setOnClickListener {
            // 跳转到flutter
            val options = FlutterBoostRouteOptions.Builder()
                .pageName("debug")
                .arguments(HashMap())
                .requestCode(1111)
                .build()
            FlutterBoost.instance().open(options)
        }
        findViewById<View>(R.id.gotoRDFlutterApp).setOnClickListener {
            // 跳转到flutter
            val options = FlutterBoostRouteOptions.Builder()
                .pageName("rd")
                .arguments(HashMap())
                .requestCode(1111)
                .build()
            FlutterBoost.instance().open(options)
        }
    }

    override fun onResume() {
        super.onResume()
        findViewById<View>(R.id.gotoFlutterBoost).post {
            findViewById<View>(R.id.gotoFlutterBoost).callOnClick()
        }
    }

}